#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        if(s.size()==0){
            return 0;
        }
        map<char,int> T;
        int maxSize = 0;
        int i = 0;
        int size = s.size();
        while(i<size){
            if(T.find(s[i])==T.end()){
                T[s[i]] = i;
                i = i+1;
            }
            else{
                maxSize = max(maxSize,int(T.size()));
                vector<char> V;
                int index = T[s[i]];
                for(map<char,int>::iterator i = T.begin();i!=T.end();++i){
                    if(i->second<=index){
                        V.push_back(i->first);
                    }
                }
                for(int i = 0;i<V.size();++i){
                    T.erase(V[i]);
                }
                T[s[i]] = i;
                i=i+1;
            }

        }
        return max(maxSize,int(T.size()));
    }

   
};

int main(){
    string s = "abcabcbb";
    Solution S;
    cout<<S.lengthOfLongestSubstring(s)<<endl;
}